<?php
/*
 * @Author: your name
 * @Date: 2020-06-06 09:12:55
 * @LastEditTime: 2020-06-07 10:26:17
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \hotel\application\api\controller\Base.php
 */ 
namespace app\api\controller;
use think\Controller;
use think\Request;
class Base extends Controller{
    
    public $user_id;

    public function _initialize()
    {

        error_reporting(0);
        // 制定允许其他域名访问
        header("Access-Control-Allow-Origin:*");
        // 允许的响应类型
        header('Access-Control-Allow-Methods: GET, POST, PUT,DELETE,OPTIONS,PATCH');
        // 响应头设置
        header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization");
       
        
        $this->user_id = session("user_id");
        if(empty($this->user_id)){
            $this->user_id =  Request::instance()->header('token');
        }
        //$this->user_id = 19;
        if(empty($this->user_id)){
            exit(json_encode(['code'=>-1,'msg'=>'请登录']));
        }else{
            
            $user=db("user")->where(['user_id'=>$this->user_id])->find();
            
            vipnumber($this->user_id);
            
            if(empty($user)){
                session("user_id",null); 
                exit(json_encode(['code'=>-1,'msg'=>'请登录']));
            }
            if($user['user_status']==1){ 
                exit(json_encode(['code'=>0,'msg'=>'账号被禁用']));
            }
            
        }
        
    }

     
    
}
 